const req = (funName, params, showLoading = false) => {
	// showLoading  加载动画 默认不开启
	// const token = uni.getStorageSync('userInfo')
	// if(!token){
	// 	//没有token 跳转登陆
	// 	uni.reLaunch({
	// 		url: "/pages/login/index"
	// 	})
	// }
	return new Promise((resolve , reject) => {

		if (showLoading) {
			uni.showLoading({
				title: "loading...",
			})
		}

		uniCloud.callFunction({
			name: funName,
			data: {
				...params
			},

			success: res => {
				console.log(res, "res");
				if (res.result.code == 200) {
					if (showLoading) {
						uni.hideLoading()
					}

					let ret = {
						...res.result,
						result: res.result
					}
					resolve(ret)
				} else {
					reject(res.result.msg || '操作失败')
				}

			},
			fail: () => {
				uni.hideLoading()
				reject(false)
			}
		})
	})
}

export default req